package lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 *
 */
public class LambdaDemo1 {
    public static void main(String[] args) {
        Comparator<String> c1 = new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.length() - o2.length();
            }
        };
        //;lambda表达式写法
        Comparator<String> c2 = (String o1 ,String o2)->{
            return o2.length() - o2.length();
        };
        //lambda表达式中参数类型可以省略不写
        Comparator<String> c3 = (o1 ,o2)-> o2.length() - o1.length();
        //如果方法只有一句代码,那么方法体的"{}"可以忽略,并且如果有return一同忽略
        List<String> list = new ArrayList<>();
        list.add("02");
        list.add("古见同学");
        list.add("芙蕾雅");
        list.add("no name");
        Collections.sort(list,(o1,o2)-> o2.length() - o1.length());
        System.out.println(list);
    }
}
